﻿#ifndef DTUWINDOW_H
#define DTUWINDOW_H

#include <QtCharts>
#include <QMainWindow>
#include "chart.h"
#include "../../include/ui_utility.h"
#include "../threads/tcpthread.h"
#include "../threads/sqlthread.h"
#include "../model/dtutablemodel.h"
#include "dtusettingwidget.h"

class DTUWindow : public QWidget
{
    Q_OBJECT
public:
    DTUWindow();
    ~DTUWindow();

    //ui
    QTableView* dtuTableView;
    void setup_tableview();

    ChartManager* chartManager;
    HisChart* hisChart;

public slots:
    //rtline show
    void slt_updateCurrent(uint id, const QList<int>& data);

    //sql
    void slt_addgetId(uint);
    void confirmSetting();

signals:
    void sig_addDTU(const DTUData& data);
    void sig_deleteDTU(uint id);
    void sig_updateDTU(const DTUData& data);
    void sig_searchCurrent(const QDateTime&, const QDateTime&, uint);

private slots:
    //realtime line
    void slt_dtuSelected(const QModelIndex &index);
    //ui
    void slt_addDialog();
    void slt_searchDialog();
    void slt_exportDialog();
    //table
    void slt_showMenu(const QPoint&);
    void slt_delete();

private:
    void setup_ui();
    QToolButton* addButton;
    //dtu table
    QLayout* setup_dtutable();
    QMenu* menu;
    QAction *deleteAction;

    //dtu lines
    QLayout* setup_dtulines();
    QChartView* dtuRTLine;
    QChartView* dtuHisLine;
    QToolButton* searchButton;
    QToolButton* exportButton;
    QLabel* timelabel;
    QLayout* setup_rtline();
    QButtonGroup* rtButtonGroup;
    QLayout* setup_hisline();
    QButtonGroup* hisButtonGroup;

    //dtu setting widget
    DTUSettingWidget* dtuSettingWidget;

    //dtu model
    void setup_model();
    DTUTableModel* m_modelDTUTable;

    //ui slots
    void setup_ui_slots();
    // threads
    TCPThread* tcpThread;
    TCPThread* tcpThread2;
    SqlThread* sqlThread;

    SqlThread* uploadThread;
    SqlThread* uploadThread2;
    SqlThread* searchThread;

};


#endif // DTUWINDOW_H
